package com.yic.module.wms.dal.mysql.warehouse;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.wms.dal.dataobject.warehouse.WarehouseDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.wms.controller.admin.warehouse.vo.*;

/**
 * 仓库 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface WarehouseMapper extends BaseMapperX<WarehouseDO> {

    default PageResult<WarehouseDO> selectPage(WarehousePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WarehouseDO>()
                .likeIfPresent(WarehouseDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseDO::getCode, reqVO.getCode())
                .eqIfPresent(WarehouseDO::getStatus, reqVO.getStatus())
                .eqIfPresent(WarehouseDO::getFactoryId, reqVO.getFactoryId())
                .orderByDesc(WarehouseDO::getId));
    }

    default List<WarehouseDO> selectList(WarehouseExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<WarehouseDO>()
                .likeIfPresent(WarehouseDO::getName, reqVO.getName())
                .eqIfPresent(WarehouseDO::getCode, reqVO.getCode())
                .eqIfPresent(WarehouseDO::getStatus, reqVO.getStatus())
                .eqIfPresent(WarehouseDO::getFactoryId, reqVO.getFactoryId())
                .orderByDesc(WarehouseDO::getId));
    }

    default WarehouseDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<WarehouseDO>()
                .eq(WarehouseDO::getCode, code));
    }

    default List<WarehouseDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<WarehouseDO>()
                .inIfPresent(WarehouseDO::getId, ids)
                .inIfPresent(WarehouseDO::getStatus,statuses));
    }

    default WarehouseDO selectByErpId(String erpWarehouseId) {
        return selectOne(new LambdaQueryWrapperX<WarehouseDO>()
                .eq(WarehouseDO::getRemark, erpWarehouseId));
    }

    default List<WarehouseDO> selectListByErpId(Collection<String> erpWarehouseIds) {
        return selectList(new LambdaQueryWrapperX<WarehouseDO>()
                .inIfPresent(WarehouseDO::getRemark, erpWarehouseIds));
    }
}
